﻿using System;
using Test.Protocol;
using MessageSystem.Managed.Rpc;
using MessageSystem.Managed.Infrastructure;
using MessageSystem.Managed;

namespace FrontEnd
{
	public class PingServer : IPing,IPingAsyn
	{
		public int Ping(string content)
		{
			Console.WriteLine (content);
			return 0;
		}

		public void Ping(string content, Action<int> callback)
		{
			callback(110);
		}
	}

	class MainClass
	{
		static RpcCenter rpc;
		static RpcAddress address;
		static void Main(string[] args)
		{
			rpc = new RpcCenter(Options.Default,MessageSystemType.Default);
			address = new RpcAddress { Ip = "192.168.1.122", Port = 8001, Name = "测试域" };
			rpc.CreateDomain(address, domain =>
				{
					Console.WriteLine("GetDomain");
					PingServer pingserver = new PingServer();
					domain.BindService<PingProxy,IPing>(0,pingserver,() => { Console.WriteLine("IPing服务丢失"); });
				});
			while (true)
			{
				rpc.Poll(10);
			}
		}
	}
}
